package com.zhitong.ztblog.mappers;


import com.zhitong.ztblog.entity.Sort;
import org.apache.ibatis.annotations.*;

@Mapper
public interface SortMapper {
    //    查询所有标签
    @Results(id = "sortMap",value = {
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "name",column = "name"),
            @Result(property = "blogNum",column = "id",one = @One(select = "com.zhitong.ztblog.mappers.BlogMapper.findBlogNumBySid"))
    })
    @Select("select * from sort")
    public Sort[] findAll();

    @Select("select count(*) from sort ")
    public int findSortNum();


    //    根据id查找分类
    @ResultMap("sortMap")
    @Select("select * from sort where id =#{id}")
    public Sort findById(int id);

    @Select("select name from sort where id =#{id}")
    public String findNameById(int id);


    //随机查询五个分类,用于首页展示
    @ResultMap("sortMap")
    @Select("select * from sort order by rand() limit 5")
    public Sort[] findByRand();

    //根据id删除标签
    @Delete("delete from sort where id = #{id}")
    public void delSortById(int id);

    //添加标签
    @Insert("insert into sort value(null,#{name})")
    public void insertSort(String name);

    //    根据名称查询标签
    @Select("select count(*) from sort where name=#{name}")
    public int findSortByName(String Name);

}
